using System;
using System.IO;
using UnityEditor;
using UnityEditor.AssetImporters;
using UnityEngine;

[CustomEditor(typeof(MeshFilter))]
public class MeshExtractorEditor : Editor
{
    // [MenuItem("Assets/Extract Mesh From Selected FBX")]
    // public static void ExtractMeshFromFBX()
    // {
    //     // 获取当前选择的所有FBX文件
    //     var selectedFbxFiles = Selection.GetFiltered<GameObject>(SelectionMode.Assets);
    //     if (selectedFbxFiles.Length == 0)
    //     {
    //         Debug.LogError("No FBX files selected.");
    //         return;
    //     }
    //
    //     // 遍历每个FBX文件
    //     foreach (var fbxFile in selectedFbxFiles)
    //     {
    //         UnityEditor.AssetImporters.AssetImporterEditor.f
    //         // 检查是否是单个模型
    //         if (FBXImporter.GetAtomCount(fbxFile.name) == 1)
    //         {
    //             string assetPath = Path.Combine(Path.GetDirectoryName(AssetDatabase.GetAssetPath(fbxFile)), "extracted_mesh.asset");
    //             
    //             // 导入FBX
    //             AssetDatabase.ImportAsset(fbxFile.name);
    //             
    //             // 获取新导入的mesh
    //             MeshFilter[] meshFilters = fbxFile.GetComponentsInChildren<MeshFilter>();
    //             if (meshFilters.Length > 0)
    //             {
    //                 MeshFilter meshFilter = meshFilters[0];
    //                 Mesh mesh = meshFilter.sharedMesh;
    //                 
    //                 // 创建新的mesh资产
    //                 AssetDatabase.CreateAsset(mesh, assetPath);
    //                 AssetDatabase.SaveAssets();
    //                 AssetDatabase.Refresh();
    //                 
    //                 Debug.Log("Mesh extracted to: " + assetPath);
    //             }
    //             else
    //             {
    //                 Debug.LogError("No Mesh Filter found in the FBX file.");
    //             }
    //         }
    //         else
    //         {
    //             Debug.LogWarning("The selected FBX contains multiple models. Only single model FBX files are supported for now.");
    //         }
    //     }
    // }
}